<?php
/**
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file license.txt or that can be found at 
 * http://code.google.com/p/billboardce/wiki/License.
 *
 * @package    Marquee_Module
 * @category   Model
 * @license    http://code.google.com/p/billboardce/wiki/License New BSD License
 * @version    SVN: $Id: $
 */
class Slidestream_Plugin_Marquee extends Bbce_Slidestream_Plugin_Abstract
{
    /**
     * Title of the plugin, as shown in the interface
     * 
     * @var string
     */    
    protected $_title = 'Marquee';
    
    /**
     * Description of the plugin, as shown in the interface
     * 
     * @var string
     */    
    protected $_description = 'Displays a scrolling banner on the slidestream.';
    
    /**
     * Generates a Zend_Form object which is displayed when
     * editing the given plugin.  The $values array is
     * a key => value associative array that maps the form
     * field names with their default values, if any.
     * 
     * @param array $values
     * @return object Zend_Form
     */    
    public function getConfigurationForm($values = array())
    {
        $marqueeTypes = array(
            'text'   => 'Text',
            'rss'    => 'RSS Feed',
            //'custom' => 'Custom URL',
        ); 

        $form = new Zend_Form();
        $form->setAttrib('class', 'slidestreamOptionForm')
             ->setDecorators(array(
                     'FormElements',
                     array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')),
                     'Form'
             ));
             
        $enabled = $form->createElement('select', 'enabledMarquee', array('label' => 'Enabled:'));
        $enabled->setMultiOptions(array(
                '0' => 'No',
                '1' => 'Yes'
               ))
             ->setValue(isset($values['enabled']) ? $values['enabled'] : '0');
             
        $type = $form->createElement('select', 'typeMarquee', array('label' => 'Type:'));
        $type->setRequired(false)
             ->setMultiOptions($marqueeTypes)
             ->setValue(isset($values['type']) ? $values['type'] : 'text');
             
        $text = $form->createElement('textarea', 'textMarquee', array('label' => 'Text:'));
        $text->setRequired(false)
             ->setDescription('Add each message on a new line')
             ->setValue(isset($values['text']) ? $values['text'] : '');

        $url = $form->createElement('text', 'urlMarquee', array('label' => 'URL:'));
        $url->setRequired(false)
            ->setDescription('The URL to an RSS feed')
            ->setValue(isset($values['url']) ? $values['url'] : '');
            
        $rssMode = $form->createElement('select', 'rssModeMarquee', array('label' => 'RSS Display Mode:'));
        $rssMode->setMultiOptions(array(
                  'title'        => 'Title Only',
                  'titleSnippet' => 'Title + Snippet',
                  'snippet'      => 'Snippet Only'
                ))
                ->setDescription('How to display the RSS feed data')
                ->setValue(isset($values['rssMode']) ? $values['rssMode'] : 'title');
            
        $position = $form->createElement('select', 'positionMarquee', array('label' => 'Position:'));
        $position->setRequired(false)
                 ->addMultiOption('bottom', 'Bottom')
                 ->addMultiOption('top', 'Top')
                 ->setValue(isset($values['position']) ? $values['position'] : 'bottom');

        $fontFamily = $form->createElement('select', 'fontFamilyMarquee', array('label' => 'Font:'));
        $fontFamily->setMultiOptions(array(
                  'Arial'                   => 'Arial',
                  'Cantarell'               => 'Cantarell',
                  'Cardo'                   => 'Cardo',
                  'Courier'                 => 'Courier',
                  'Crimson Text'            => 'Crimson Text',
                  'Cuprum'                  => 'Cuprum',
                  'Droid Sans'              => 'Droid Sans',
                  'Droid Serif'             => 'Droid Serif',
                  'Helvetica'               => 'Helvetica',
                  'IM Fell'                 => 'IM Fell',
                  'Inconsolata'             => 'Inconsolata',
                  'Josefin Sans Std Light'  => 'Josefin Sans Std Light',
                  'Lobster'                 => 'Lobster',
                  'Molengo'                 => 'Molengo',
                  'Neucha'                  => 'Neucha',
                  'Neuton'                  => 'Neuton',
                  'Nobile'                  => 'Nobile',
                  'OFL Sorts Mill Goudy TT' => 'OFL Sorts Mill Goudy TT',
                  'Old Standard TT'         => 'Old Standard TT',
                  'PT Sans'                 => 'PT Sans',
                  'Philosopher'             => 'Philosopher',
                  'Reenie Beanie'           => 'Reenie Beanie',
                  'Tangerine'               => 'Tangerine',
                  'Verdana'                 => 'Verdana',
                  'Vollkorn'                => 'Vollkorn',
                  'Yanone Kaffeesatz'       => 'Yanone Kaffeesatz'
                ))
                ->setDescription('See http://code.google.com/webfonts for more information')
                ->setValue(isset($values['fontFamily']) ? $values['fontFamily'] : 'Arial');
            
        $fontSize = $form->createElement('select', 'fontSizeMarquee', array('label' => 'Font Size:'));
        $fontSize->setMultiOptions(array(
                  '24' => '24px',
                  '28' => '28px',
                  '30' => '30px',
                  '32' => '32px',
                  '34' => '34px',
                  '36' => '36px',
                  '38' => '38px',
                  '40' => '40px',
                  '42' => '42px',
                  '48' => '48px',
                  '52' => '55px',
                  '60' => '60px',
                  '72' => '72px'
                ))
                ->setValue(isset($values['fontSize']) ? $values['fontSize'] : '38');        
                 
        $textColor = $form->createElement('text', 'textColorMarquee', array('label' => 'Text Color:'));
        $textColor->setAttrib('size', 6)
                  ->setAttrib('maxlength', 6)
                  ->setAttrib('class', 'color');
        $textColor->setValue(isset($values['textColor']) ? $values['textColor'] : 'FFFFFF');                 
                 
        $bgColor = $form->createElement('text', 'bgColorMarquee', array('label' => 'Background Color:'));
        $bgColor->setAttrib('size', 6)
                ->setAttrib('maxlength', 6)
                ->setAttrib('class', 'color');
        $bgColor->setValue(isset($values['bgColor']) ? $values['bgColor'] : '000000');

        $opacity = $form->createElement('select', 'opacityMarquee', array('label' => 'Opacity:'));
        
        for ($x = 0; $x <= 100; $x+=5) {
            $opacity->addMultiOption(($x / 100), $x);
        }
        
        $opacity->setValue(isset($values['opacity']) ? $values['opacity'] : '1');
        
        $effect = $form->createElement('select', 'effectMarquee', array('label' => 'Effect:'));
        $effect->setMultiOptions(array(
                'roll' => 'Roll',
                'crawl' => 'Crawl'
               ))
             ->setValue(isset($values['effect']) ? $values['effect'] : 'roll');
        
        $form->addElements(array($enabled, $type, $text))
             ->addDisplayGroup(array('textMarquee'), 'textDisplayGroupMarquee')
             ->addElements(array($url, $rssMode))
             ->addDisplayGroup(array('urlMarquee', 'rssModeMarquee'), 'urlDisplayGroupMarquee')
             ->addElements(array($position, $fontFamily, $fontSize, $textColor, $bgColor, $opacity, $effect));
             
        $form->getDisplayGroup('textDisplayGroupMarquee')->removeDecorator('DtDdWrapper');
        $form->getDisplayGroup('urlDisplayGroupMarquee')->removeDecorator('DtDdWrapper');

        $form->setElementDecorators(array(
                  'ViewHelper',
                  'Errors',
                  array('HtmlTag', array('tag' => 'div', 'class' => 'elm')),
                  array('Label', array('tag' => 'span')),
                  array('Description', array('tag' => 'div', 'class' => 'elmDescription'))
              ));
        
        return $form;
    }
}